import { createRouter, createWebHistory } from 'vue-router'

export const Layout = () => import('@/Layout/index.vue')
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/Login/index.vue')
    },
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: 'home',
          name: 'Home',
          component: () => import('@/views/Home/index.vue'),
          meta: { title: '首页' }
        },
        {
          path: 'btns',
          name: 'btns',
          component: () => import('@/views/btns/index.vue'),
          meta: { title: 'zz' }
        }
      ]
    },
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: 'room',
          name: 'room',
          component: () => import('@/views/room/index.vue'),
          meta: { title: '组织架构', icon: 'tree' }
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  next()
})
router.afterEach((to, from) => {
  if (to.meta && to.meta.title) {
    document.title = `Bing 管理系统-${to.meta.title}`
  }
})
export default router
